package com.maoslv.service.order;

import com.maoslv.mapper.OrderMapper;
import com.maoslv.pojo.Order;
import com.maoslv.pojo.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    OrderMapper orderMapper;

    @Override
    public int addOrder(Order order) {
        order.setCreateTime(new Date());
        return orderMapper.addOrder(order);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map<String,Object> getOrderList(Pagination pagination) {
        pagination.setCurrentPage((pagination.getCurrentPage() - 1) * pagination.getPageSize());
        List<Order> orderList = orderMapper.getOrderList(pagination);
        Integer total = orderMapper.getTotal(pagination);
        Map<String, Object> map = new HashMap<>();
        map.put("orderList",orderList);
        map.put("total",total);
        return map;
    }

    @Override
    public int updateOrder(Integer id, Integer examine) {
        return orderMapper.updateOrder(id, examine);
    }
}
